﻿using System;
using System.IO;
using Cassini;

namespace Pyxis.FluentSelenium.SampleWebAppTest
{
    public class WebApplication
    {
        private readonly Server webServer;

        public WebApplication(int serverPort, string webApplicationPath)
        {
            var appPath = GetApplicationPath(webApplicationPath);
            webServer = new Server(serverPort, "/", appPath);
        }

        public void Start()
        {
            webServer.Start();
        }

        public void Stop()
        {
            webServer.Stop();
        }

        public string GetApplicationPath(string webProjectPath)
        {
            return Path.Combine(FullSourcePath, webProjectPath + "\\");
        }

        private static string FullSourcePath
        {
            get
            {
                var fullSourcePath = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\");
                return Path.GetFullPath(fullSourcePath);
            }
        }
    }
}